from dashscope import Generation

# 替换为你自己的 API Key
DASHSCOPE_API_KEY = "sk-b7ea72f6474c4264a55dd3118be895c2"

def chat_with_qwen(prompt):
    try:
        response = Generation.call(
            api_key=DASHSCOPE_API_KEY,
            model="qwen-max",  # 可选: qwen-turbo / qwen-plus / qwen-max
            prompt=prompt,
            sys_prompt="你是一个有用的助手。",
            temperature=0.7,
            top_p=0.8
        )
        return response.output.text.strip()
    except Exception as e:
        return f"发生错误：{e}"

if __name__ == "__main__":
    user_input = input("你：")
    reply = chat_with_qwen(user_input)
    print(f"Qwen：{reply}")